package com.ruoyi.wechat.service.impl;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.ruoyi.wechat.domain.Camp;
import com.ruoyi.wechat.domain.Message;
import com.ruoyi.wechat.mapper.CampMapper;
import com.ruoyi.wechat.mapper.MessageMapper;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wechat.mapper.ScenicSpotsMapper;
import com.ruoyi.wechat.domain.ScenicSpots;
import com.ruoyi.wechat.service.IScenicSpotsService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 周边景点Service业务层处理
 *
 * @author ruoyi
 * @date 2024-11-11
 */
@Service
public class ScenicSpotsServiceImpl implements IScenicSpotsService
{
    @Autowired
    private ScenicSpotsMapper scenicSpotsMapper;
    @Autowired
    private CampMapper campMapper;
    @Autowired
    private MessageMapper messageMapper;


    /**
     * 查询周边景点
     *
     * @param scenicId 周边景点主键
     * @return 周边景点
     */
    @Override
    public ScenicSpots selectScenicSpotsByScenicId(String scenicId)
    {
        return scenicSpotsMapper.selectScenicSpotsByScenicId(scenicId);
    }

    /**
     * 查询周边景点列表
     *
     * @param scenicSpots 周边景点
     * @return 周边景点
     */
    @Override
    public List<ScenicSpots> selectScenicSpotsList(ScenicSpots scenicSpots)
    {
        return scenicSpotsMapper.selectScenicSpotsList(scenicSpots);
    }

    /**
     * 新增周边景点
     *
     * @param scenicSpots 周边景点
     * @return 结果
     */
    @Override
    public int insertScenicSpots(ScenicSpots scenicSpots)
    {
        scenicSpots.setScenicId(UUID.randomUUID().toString());
        return scenicSpotsMapper.insertScenicSpots(scenicSpots);
    }

    /**
     * 修改周边景点
     *
     * @param scenicSpots 周边景点
     * @return 结果
     */
    @Override
    public int updateScenicSpots(ScenicSpots scenicSpots)
    {
        return scenicSpotsMapper.updateScenicSpots(scenicSpots);
    }

    /**
     * 批量删除周边景点
     *
     * @param scenicIds 需要删除的周边景点主键
     * @return 结果
     */
    @Override
    public int deleteScenicSpotsByScenicIds(String[] scenicIds)
    {
        return scenicSpotsMapper.deleteScenicSpotsByScenicIds(scenicIds);
    }

    /**
     * 删除周边景点信息
     *
     * @param scenicId 周边景点主键
     * @return 结果
     */
    @Override
    public int deleteScenicSpotsByScenicId(String scenicId)
    {
        return scenicSpotsMapper.deleteScenicSpotsByScenicId(scenicId);
    }

    @Transactional
    @Override
    public int approveSpots(Message message){
        //查询景点
    ScenicSpots spots = scenicSpotsMapper.selectScenicSpotsByScenicId(message.getScenicId());
    //查询营地
    Camp camp = campMapper.selectCampByCampId(message.getCampId());
    //id
    message.setMessageId(UUID.randomUUID().toString());
    //审核时间
    message.setReleaseTime(new Date());

    //审核内容
  String content=  message.getApprove().equals("1")?"审核通过，"+message.getContent():"审核失败,"+message.getContent();

  message.setContent("景点审核消息：”“+camp.getCampName()+”“营地的”“+spots.getScenicName()+”“景点"+content);
  message.setUserId(camp.getUserId());
  messageMapper.insertMessage(message);
  spots.setApprove(message.getApprove());
  scenicSpotsMapper.updateScenicSpots(spots);
  return 1;



}
}
